home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / news / inn1.000 / inn1.4sec-linux-src.tar / inn / lib / xwritev.c < prev   
C/C++ Source or Header  |  1992-10-29  |  864b  |  42 lines

  1. /*  $Revision: 1.3 $
  2. **
  3. */
  4. #include <stdio.h>
  5. #include <errno.h>
  6. #include <sys/types.h>
  7. #include <sys/uio.h>
  8. #include "clibrary.h"
  9.  
  10.  
  11. /*
  12. **  Do a writev, return -1 on error; 0 if okay.  Handling the return value
  13. **  of writev is a pain.  It should return the number of iov's it fully
  14. **  wrote out, and update the fields in all of them to contain the new
  15. **  startpoints.
  16. */
  17. int
  18. xwritev(fd, vp, vpcount)
  19.     int            fd;
  20.     struct iovec    *vp;
  21.     register int    vpcount;
  22. {
  23.     register int    i;
  24.     register long    left;
  25.  
  26.     /* Get the total bytecount. */
  27.     for (left = 0, i = vpcount; --i >= 0; )
  28.     left += vp[i].iov_len;
  29.  
  30.     while (vpcount) {
  31.     if ((i = writev(fd, vp, (SIZE_T)vpcount)) < 0)
  32.         return -1;
  33.     if ((left -= i) <= 0)
  34.         break;
  35.     for (; i >= vp->iov_len; vp++, vpcount--)
  36.         i -= vp->iov_len;
  37.     vp->iov_base += i;
  38.     vp->iov_len -= i;
  39.     }
  40.     return 0;
  41. }
  42.